#!/usr/bin/perl

#$file = $ARGV[0];
#open fd, "<$file" or die "cannot open file\n";

while (<STDIN>) {
	chomp;
	@rs = split;
	$pctimestamp = $rs[0];
	$amtype = hex("$rs[20]");
	$src = hex("$rs[18]$rs[17]");
	$dest = hex("$rs[16]$rs[15]");
	$destpan = hex("$rs[14]$rs[13]");
	$dsn = hex("$rs[12]");
	$fcf = hex("$rs[11]$rs[10]");
	$len = hex("$rs[9]"); # total msg length NOT including the len field (CRC:2)
	
	$sntimestamp = hex("$rs[-1]$rs[-2]$rs[-3]$rs[-4]");
	
	if ($amtype == 0x71) { # ctp data
		$mytype = hex("$rs[29]");
                $d1 = hex("$rs[74]")-0x30;
                $d2 = hex("$rs[75]")-0x30;
                $d3 = hex("$rs[76]")-0x30;
                $d4 = hex("$rs[77]")-0x30;
                $d5 = hex("$rs[78]")-0x30;
                if ($mytype==0xc1) { $cpu_sleep = hex("$rs[51]$rs[52]$rs[53]$rs[54]"); }
                else { $cpu_sleep=0; }

#                if ($mytype == 0xc1) {

		print "$pctimestamp/$sntimestamp $src->$dest CTP DATA[$len] $mytype CO2=$d1$d2$d3$d4$d5($rs[71] $rs[72] $rs[73] $rs[74] $rs[75] $rs[76] $rs[77] $rs[78]) task_time=$cpu_sleep($rs[51]$rs[52]$rs[53]$rs[54])\n";

#                }
	}
	elsif ($amtype == 0x70) {
		print "$pctimestamp/$sntimestamp $src CTP beacon\n";
	}
	elsif ($len == 5) {
		print "$pctimestamp/$sntimestamp ACK\n";
	}
	elsif ($amtype == 0x60) {
		print "$pctimestamp/$sntimestamp $src Drip beacon\n";
	}
        elsif ($amtype == 0x07) { # GPS data
          # 23->  
          print "timestamp:";
          $start = 23;
          for (my $i=0; $i<12; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print " weidu:";
          $start = 35;
          for (my $i=0; $i<13; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print " jingdu:";
          $start = 48;
          for (my $i=0; $i<13; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print " gaodu:";
          $start = 61;
          for (my $i=0; $i<12; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print " num:";
          $start = 73;
          for (my $i=0; $i<3; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print " dim:";
          $start = 76;
          for (my $i=0; $i<1; $i++) {
            printf "%c", hex("$rs[$start+$i]");
          }
          
          print "\n";
        }
	else {
           print "[$len] ";
		print "$_\n";
	}
}

#close fd;

